package command;

/** 命令设计模式
 * @author chenyuan
 * @date 2020/10/29 15:50
 */

public class Client {
    // 使用命令设计模式，通过遥控器，实现对电灯的操作
    public static void main(String[] args) {
        // 创建电灯对象（接收者）
        LightReceiver lightReceiver = new LightReceiver();

        // 创建电灯相关的开关命令
        LightOnCommand onCommand = new LightOnCommand(lightReceiver);
        LightOffCommand offCommand = new LightOffCommand(lightReceiver);

        // 创建遥控器
        RemoteController controller = new RemoteController();

        // 给遥控器设置相关命令
        controller.SetCommand(0, onCommand, offCommand);

        System.out.println("++++++按下灯的开按钮+++++");
        controller.OnButtonClicked(0);
        System.out.println("++++++按下灯的关按钮+++++");
        controller.OffButtonClicked(0);
        System.out.println("++++++按下撤销按钮+++++");
        controller.undoButtonClicked(0);
    }
}
